package com.htgd.gardenexpo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htgd.gardenexpo.dao.GeBaseDictDao;
import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConThemeActivity;
import com.htgd.gardenexpo.dao.GeConThemeActivityMapper;
import com.htgd.gardenexpo.page.RecommendQuery;
import com.htgd.gardenexpo.page.ThemeActivityQuery;
import com.htgd.gardenexpo.service.GeBaseDictService;
import com.htgd.gardenexpo.service.IGeConThemeActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.htgd.gardenexpo.vo.GeConThemeActivityVO;
import com.htgd.gardenexpo.vo.RecommendVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 主题活动 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-01-06
 */
@Service
public class GeConThemeActivityServiceImpl extends ServiceImpl<GeConThemeActivityMapper, GeConThemeActivity> implements IGeConThemeActivityService {

    @Autowired
    private GeConThemeActivityMapper geConThemeActivityMapper;

    @Autowired
    private GeBaseDictDao geBaseDictDao;

    @Override
    public CommonResult add(GeConThemeActivity geConThemeActivity, String username) {
        //默认值
        geConThemeActivity.setCreateUser(username);
        geConThemeActivity.setStatus("4");

        geConThemeActivityMapper.insert(geConThemeActivity);

        return CommonResult.success("添加成功");
    }

    @Override
    public CommonResult edit(GeConThemeActivity geConThemeActivity) {
        geConThemeActivityMapper.updateById(geConThemeActivity);

        return CommonResult.success("编辑成功");
    }

    @Override
    public CommonResult delete(String id) {
        geConThemeActivityMapper.deleteById(id);

        return CommonResult.success("删除成功");

    }

    @Override
    public PageInfo<GeConThemeActivityVO> pageList(ThemeActivityQuery themeActivityQuery) {
        PageHelper.startPage(themeActivityQuery.getPageNum(),themeActivityQuery.getPageSize());
        List<GeConThemeActivityVO> list = geConThemeActivityMapper.pageList(themeActivityQuery);
        for (GeConThemeActivityVO geConThemeActivityVO : list) {
            if(("1".equals(geConThemeActivityVO.getIsRecommend()))){
                geConThemeActivityVO.setIsRecommendText("推荐");
            }else {
                geConThemeActivityVO.setIsRecommendText("不推荐");
            }
        }
        return new PageInfo<>(list);
    }

    @Override
    public CommonResult<GeConThemeActivityVO> details(String id) {
        GeConThemeActivityVO geConThemeActivityVO = new GeConThemeActivityVO();

        GeConThemeActivity geConThemeActivity = geConThemeActivityMapper.selectById(id);
        BeanUtils.copyProperties(geConThemeActivity,geConThemeActivityVO);

        return CommonResult.success("查询成功",geConThemeActivityVO);
    }

    @Override
    public CommonResult review(GeConThemeActivity geConThemeActivity) {
        lambdaUpdate().eq(GeConThemeActivity::getId,geConThemeActivity.getId())
                .set(GeConThemeActivity::getStatus,geConThemeActivity.getStatus())
                .update();

        return CommonResult.success("审核成功");
    }

    @Override
    public List<RecommendVO> getRecommendList(RecommendQuery recommendQuery) {
        return geConThemeActivityMapper.getRecommendList(recommendQuery);
    }
}
